;; ;; -------- extend eshell --------
;; (use-package aweshell
;;   :load-path "lazycat-bucket/aweshell"
;;   :config
;;   (add-hook 'eshell-mode-hook
;; 	    (lambda ()
;; 	      (define-key term-raw-map (kbd "C-p") 'eshell-previous-matching-input-from-input)
;; 	      (define-key term-raw-map (kbd "C-n") 'eshell-next-matching-input-from-input))))

;; -------- term simulator & shell script --------
(cond
 ((string-equal system-type "gnu/linux")
  (use-package multi-term
    :init
    (setq multi-term-program "/usr/bin/zsh"
          multi-term-scroll-show-maximum-output 1000)
    :bind
    (("<f12>" . 'p1uxtar-open-term))
    :config
    (defun p1uxtar-open-term ()
      (interactive)
      (let ((p1uxtar-term-name "*Terminal*"))
        (if (get-buffer p1uxtar-term-name)
            (pop-to-buffer p1uxtar-term-name)
          (multi-term)
          (with-current-buffer "*terminal<1>*"
            (rename-buffer p1uxtar-term-name)))))
    (add-hook 'term-mode-hook
              (lambda ()
                (define-key term-raw-map (kbd "<f12>") 'previous-buffer)
                (define-key term-raw-map (kbd "C-o") 'ace-window)
                (define-key term-raw-map (kbd "C-p") 'term-send-up)
                (define-key term-raw-map (kbd "C-n") 'term-send-down)
                (define-key term-raw-map (kbd "M-DEL") 'term-send-backward-kill-word)))))
 ((eq system-type 'windows-nt)
  (defun p1uxtar-open-eshell ()
    (interactive)
    (let ((p1uxtar-term-name "*eshell*"))
      (if (get-buffer p1uxtar-term-name)
          (pop-to-buffer p1uxtar-term-name)
        (eshell))))
  (global-set-key (kbd "<f12>") 'p1uxtar-open-eshell)
  (add-hook 'eshell-mode-hook
            (lambda ()
              (define-key eshell-mode-map (kbd "<f12>") 'previous-buffer)
              (define-key eshell-mode-map (kbd "C-o") 'ace-window)
              (define-key eshell-mode-map (kbd "C-p") 'eshell-previous-matching-input-from-input)
              (define-key eshell-mode-map (kbd "C-n") 'eshell-next-matching-input-from-input)
              (define-key eshell-mode-map (kbd "C-u") 'eshell-kill-input)))))

(provide '+sh)
